import 'package:flutter/material.dart';

class Test_listview_separated extends StatelessWidget {
  const Test_listview_separated({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text('Test_listview_separated')),
        body:ListView3()
    );
  }
}



class ListView3 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // 下划线widget预定义以供复用。
    Widget divider1=Divider(color: Colors.blue);
    Widget divider2=Divider(color: Colors.green);
    return ListView.separated(

      // 预购建缓存的item数量
      cacheExtent: 250,
      itemCount: 100,
      //列表项构造器
      itemBuilder: (BuildContext context, int index) {
        return ListTile(title: Text("$index"));
      },
      //分割器构造器
      separatorBuilder: (BuildContext context, int index) {
        return index%2==0?divider1:divider2;
      },
    );
  }
}